<template>
	<view class="content">
		<view class="login-bg">
			<view class="login-card">
				<view class="login-head">智慧设备资源预约系统</view>
				<view class="login-input login-margin-b">
					<input type="username" v-model="username" placeholder="请输入你的账户" />
				</view>
				<view class="login-input">
					<input type="password" v-model="password" placeholder="请输入你的密码" />
				</view>
				<view class="login-function">
					<view class="login-forget" @click="go_forget">忘记密码</view>
					<view class="login-register" @click="go_register">快速注册></view>
				</view>
			</view>
		</view>
		<view class="login-btn">
			<button class="landing" type="primary" @tap="login()">登录</button>
		</view>
	</view>
</template>

<script>
	import service from '../../service.js';
	import {
		mapState,
		mapMutations
	} from 'vuex'
	import store from '../../store/index.js'
	export default {
		components: {
			
		},
		data() {
			return {
				title: 'Hello',
				username: '',
				password: ''
			}
		},
		onLoad() {

		},
		computed: mapState(['userName','userId','mess']),
		methods: {
			login() {
				if (this.username == 0 || this.password == 0) {
					uni.showToast({
						title: '请输入账号或密码',
						icon: 'none',
						duration: 2000
					});
					return;
				}
				uni.request({
					url: "http://115.159.219.165:8080/login/auth",
					data: {
						username: this.username,
						password: this.password
					},
					method: 'POST',
					success: function(res) {
						//let list = JSON.stringify(res.data);
						console.log(res); 
						//console.log("list:" + list);
						if (res.data.info.result == "fail") {
							uni.showToast({
								icon: 'none',
								title: '账号或密码错误'
							});
							return; 
						}
						uni.switchTab({
							url: '../main/main',
						});
						uni.showToast({
							title: '登录成功',
							icon: 'success',
							duration: 2000
						});
						store.commit('setUserName', res.data.info.username);
						console.log(store.state.userName);
						store.commit('setUserId', res.data.info.mess.userId);
						console.log(store.state.userId);
						store.commit('setMess', res.data.info.mess);
						console.log(store.state.info.mess);
						//console.log(this.$store.state.userId);
					}
				})
			},
			go_forget(){
				uni.navigateTo({
				    url: '../../pages/password/password'
				})
			},
			go_register(){
				uni.navigateTo({
					url: '../../pages/register/register'
				})
			}
		}
	}
</script>

<style>
	.landing{
		height: 84upx;
		line-height: 84upx;
		border-radius: 44upx;
		font-size: 32upx;
		background: linear-gradient(left,#0faeff, #87CEEB);
	}
	.login-btn{
		padding: 10upx 20upx;
		margin-top: 350upx;
	}
	.login-function{
		overflow: auto;
		padding: 20upx 20upx 30upx 20upx;
	}
	.login-forget{
		float: left;
		font-size: 26upx;
		color: #999;
	}
	.login-register{
		color: #666;
		float: right;
		font-size: 26upx;

	}
	.login-input input{
		background: #F2F5F6;
		font-size: 28upx;
		padding: 10upx 25upx;
		height: 62upx;
		line-height: 62upx;
		border-radius: 8upx;
	}
	.login-margin-b{
		margin-bottom: 25upx;
	}
	.login-input{
		padding: 10upx 20upx;
	}
	.login-head{
		color: $light_gray;
		padding: 25upx 10upx 55upx 10upx;
		font-size: 26px;
		text-align: center;
		font-weight: bold;
	}
	.login-card{
		background: #fff;
		border-radius: 12upx;
		padding: 10upx 25upx;
		box-shadow: 0 6upx 18upx rgba(0,0,0,0.12);
		position: relative;
		margin-top: 120upx;
	}
	.login-bg {
		height: 260upx;
		padding: 25upx;
		background: linear-gradient(#0faeff, #87CEEB);
	}
</style>
